/**
 * 
 */
package com.zznode.client.wlanpolling.service;

import com.zznode.client.wlanpolling.EnumRunMode;
import com.zznode.client.wlanpolling.utils.WLanPollingUtils;
import com.zznode.client.wlanpolling.utils.WifiUtils;

import android.net.wifi.ScanResult;
import android.net.wifi.SupplicantState;
import android.net.wifi.WifiInfo;

/**
 * @author Bean
 * 
 */
public class Wifi {
	private String BSSID;
	private String SSID;
	private String capabilities;
	private int frequency;
	private int level;

	private String macAddress;
	private String ipAddress;
	private int linkSpeed;
	private int networkId;
	private int rssi;
	private SupplicantState supplicantState;
	
	private boolean tested = false;
	private boolean commited = false;
	
	private boolean opened = false;
	private boolean unkown = true;
	
	private ScanResult scanResult;
	private boolean selected = false;
	
	public Wifi(ScanResult scanResult, WifiInfo info) {
		this.scanResult = scanResult;
		
		if(scanResult != null) {
			this.BSSID = scanResult.BSSID;
			this.capabilities = scanResult.capabilities;
			this.frequency = scanResult.frequency;
			this.SSID = scanResult.SSID;
			this.level = scanResult.level;
		}
		
		if(info != null) {
			this.macAddress = info.getMacAddress();
			
			this.ipAddress = WifiUtils.getIpAddress(info.getIpAddress());
			this.linkSpeed = info.getLinkSpeed();
			this.networkId = info.getNetworkId();
			this.rssi = info.getRssi();
			this.supplicantState = info.getSupplicantState();
			if(WLanPollingUtils.RUN_MODE == EnumRunMode.DEBUG) {
				this.BSSID = WLanPollingUtils.DEBUG_WIFI;
			} else {
				this.BSSID = info.getBSSID();
			}
			this.SSID = info.getSSID();
		}
	}
	
	public String getBSSID() {
		return BSSID;
	}

	public void setBSSID(String bSSID) {
		BSSID = bSSID;
	}

	public String getSSID() {
		return SSID;
	}

	public void setSSID(String sSID) {
		SSID = sSID;
	}

	public String getCapabilities() {
		return capabilities;
	}

	public void setCapabilities(String capabilities) {
		this.capabilities = capabilities;
	}

	public int getFrequency() {
		return frequency;
	}

	public void setFrequency(int frequency) {
		this.frequency = frequency;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public String getMacAddress() {
		return macAddress;
	}

	public void setMacAddress(String macAddress) {
		this.macAddress = macAddress;
	}

	public String getIpAddress() {
		return ipAddress;
	}

	public void setIpAddress(String ipAddress) {
		this.ipAddress = ipAddress;
	}

	public int getLinkSpeed() {
		return linkSpeed;
	}

	public void setLinkSpeed(int linkSpeed) {
		this.linkSpeed = linkSpeed;
	}

	public int getNetworkId() {
		return networkId;
	}

	public void setNetworkId(int networkId) {
		this.networkId = networkId;
	}

	public int getRssi() {
		return rssi;
	}

	public void setRssi(int rssi) {
		this.rssi = rssi;
	}

	public SupplicantState getSupplicantState() {
		return supplicantState;
	}

	public void setSupplicantState(SupplicantState supplicantState) {
		this.supplicantState = supplicantState;
	}

	public boolean isSelected() {
		return selected;
	}

	public void setSelected(boolean selected) {
		this.selected = selected;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((BSSID == null) ? 0 : BSSID.hashCode());
		result = prime * result + ((SSID == null) ? 0 : SSID.hashCode());
		return result;
	}

	public boolean isTested() {
		return tested;
	}

	public void setTested(boolean tested) {
		this.tested = tested;
	}

	public boolean isOpened() {
		return opened;
	}

	public void setOpened(boolean opened) {
		this.opened = opened;
	}

	public ScanResult getScanResult() {
		return scanResult;
	}

	public boolean isUnkown() {
		return unkown;
	}

	public void setUnkown(boolean unkown) {
		this.unkown = unkown;
	}

	public boolean isCommited() {
		return commited;
	}

	public void setCommited(boolean commited) {
		this.commited = commited;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Wifi other = (Wifi) obj;
		if (BSSID == null) {
			if (other.BSSID != null)
				return false;
		} else if (!BSSID.equals(other.BSSID))
			return false;
		if (SSID == null) {
			if (other.SSID != null)
				return false;
		} else if (!SSID.equals(other.SSID))
			return false;
		return true;
	}
	

	public String toString() {
		StringBuffer sb = new StringBuffer();
		
		sb.append("WIFI[SSID=").append(SSID).append(",");
		sb.append("BSSID=").append(BSSID).append(",");
		sb.append("IP=").append(ipAddress==null?"":ipAddress).append("]");
		
		return sb.toString();
	}
}
